home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / STRCLASS.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  3KB  |  60 lines

  1. #ifndef __STRCLASS__    // This insures that String class
  2. #define __STRCLASS__    // is not defined more than once
  3.                         // in case this header file is
  4.                         // included by more than one
  5.                         // source  file.
  6. #include <iostream.h>
  7. #include "object.h"  
  8.  
  9. extern const Class class_String;
  10. ////////////////////////////////////////////////////////////
  11. // class String (declaration)
  12. ////////////////////////////////////////////////////////////
  13. class String : public Object
  14. {
  15. private:
  16.     char *str;      // A traditional string
  17.     int  iSize;     // Size of str buffer
  18.     int  *refs;     // Number of references to str
  19. public:
  20.                     // constructors, destructors
  21.                     String(const String &s);
  22.                     String(const int length=0);
  23.                     String(const char *s);
  24.                     ~String();
  25.  
  26.                     // operators
  27.     String          &operator=(const String &s);
  28.     String          &operator=(const char *s);
  29.     friend int      operator==(const String &s1, const String &s2);
  30.     friend int      operator!=(const String &s1, const String &s2);
  31.     friend int      operator<(const String &s1, const String &s2);
  32.     friend String&  operator+(const String &s1, const String &s2);
  33.     friend ostream& operator<<(ostream &os, const String &s);
  34.                     operator char *() const { return str; }  // cast String as char*
  35.                               
  36.  
  37.     virtual const Class*    isA()                   const;
  38.     virtual void            printOn(ostream& strm) const;
  39.  
  40.     ////////////////////////////////////////////////////////
  41.     // 4/27/93 -gmv
  42.     // Note that Smalltalk collection classes implement
  43.     // a 'size' method to indicate the number of elements
  44.     // in a collection (including the length of a string).
  45.     // However, none of the classes in the standarded
  46.     // Smalltalk collections implements a 'length' method.
  47.     // Both are provided here as synonyms since C programmers
  48.     // are likely to think in terms of length--from strlen.
  49.     ////////////////////////////////////////////////////////
  50.     unsigned                size()    const  { return iSize; }  // -gmv 4/26/93
  51.     unsigned                length()  const  { return iSize; }
  52.     void                    toUpper() const;                    // -gmv 4/26/93
  53.     void                    toLower() const;                    // -gmv 4/26/93
  54.     virtual unsigned        hash()                  const;      // -gmv 4/19/93
  55.     virtual bool            isEqual(const Object&)  const;      // -gmv 4/19/93
  56.     virtual int             compare(const Object&)  const;      // -gmv 4/19/93
  57. };
  58. #endif
  59.  
  60.